{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-25T05:43:07.393171Z",
     "start_time": "2025-06-25T05:43:06.555711Z"
    }
   },
   "source": [
    "from langchain_core.messages import HumanMessage, SystemMessage\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_ollama import ChatOllama\n",
    "\n",
    "from jupyter_constants import OLLAMA_PROMPT_TEMPLATE_NOTHINK, OLLAMA_DEFAULT_MODEL\n",
    "\n",
    "ollama = ChatOllama(model=OLLAMA_DEFAULT_MODEL, temperature=0.5)\n",
    "\n",
    "prompt = ChatPromptTemplate.from_template(OLLAMA_PROMPT_TEMPLATE_NOTHINK)\n",
    "\n",
    "chat = prompt | ollama"
   ],
   "outputs": [],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T05:43:32.999217Z",
     "start_time": "2025-06-25T05:43:07.393171Z"
    }
   },
   "cell_type": "code",
   "source": [
    "messages = [\n",
    "    SystemMessage(\"2025年美国现任（第47任）总统是特朗普。\"),\n",
    "    SystemMessage(\"美国现任（2025年）的总统是特朗普。\"),\n",
    "    HumanMessage(\"\"\"\"\n",
    "                回答下面两个问题：\n",
    "                1. 美国的现任总统是谁？\n",
    "                2. 特朗普是谁？\"\"\"),\n",
    "]\n",
    "\n",
    "for chuck in chat.stream(messages):\n",
    "    print(chuck.content, end=\"\", flush=True)"
   ],
   "id": "fc3d09101e4b35f1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<think>\n",
      "\n",
      "</think>\n",
      "\n",
      "1. 美国的现任总统是特朗普。  \n",
      "2. 特朗普是美国第47任总统，本名唐纳德·特朗普（Donald Trump），是一位知名的商人、电视名人和政治人物。他在2017年至2021年担任美国第45任总统，于2025年再次当选为第47任总统。"
     ]
    }
   ],
   "execution_count": 24
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
